import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TestDeadLock {

    public static void main(String[] args) {
        Object A = new Object();
        Object B = new Object();

        Thread t1 = new Thread(() -> {
            synchronized (A) {
                log.info("lock A...");
                try {
                    Thread.sleep(1000);
                    synchronized (B) {
                        log.info("lock B...");
                        log.info("开始操作...");
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }, "t1");
        Thread t2 = new Thread(() -> {
            synchronized (B) {
                log.info("lock B...");
                try {
                    Thread.sleep(500);
                    synchronized (A) {
                        log.info("lock A...");
                        log.info("开始操作...");
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }, "t2");

        t1.start();
        t2.start();
    }

}
